package com.ww.springboot.boot.thread.study.base.lock.aqs.demo.lock1;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2023-03-17 14:49
 */
public class LockDemo3 {

    static final MySimpleLock mySimpleLock = new MySimpleLock();

    public static void main(String[] args) {
        //创建锁 并观察同步队列中的值状态
        Thread thread = newThread();
        Thread thread2 = newThread();
        Thread thread3 = newThread();
        Thread thread4 = newThread();

        thread.start();
        thread2.start();
        thread3.start();
        thread4.start();
    }

    public static Thread newThread() {
        Thread thread = new Thread(() -> {
            mySimpleLock.lock();
            try {
                Thread.sleep(2000);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                mySimpleLock.unlock();
            }
        });
        return thread;
    }
}
